package online.inote.dic.api.dic;

import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import online.inote.dic.api.base.BaseController;
import online.inote.dic.common.annotions.Valid;
import online.inote.dic.common.utils.ResultFactory;
import online.inote.dic.model.dic.DicItemEntity;
import online.inote.dic.validator.dic.DicItemValidator;

/**
 * @description: 字典项Controller
 * @author XQF.Sui
 * @created 2019年6月10日 下午11:09:12
 * @version 1.0
 */
@RestController
@RequestMapping(value = "api/dicItem")
public class DicItemController extends BaseController<DicItemEntity, String> {

	/**
	 * @description 保存字典项
	 * @author XQF.Sui
	 * @created 2019年7月16日 下午11:27:09
	 * @param dicItem
	 * @return
	 */
	@PostMapping(value = "save")
	@Valid(validator = DicItemValidator.class)
	public ResultFactory<DicItemEntity> save(@RequestBody DicItemEntity dicItem) {
		
		if (StringUtils.isBlank(dicItem.getId())) {
			dicItem.setId(UUID.randomUUID().toString());
			service.insertSelective(dicItem);
		} else {
			service.updateByPrimaryKeySelective(dicItem);
		}
		
		return ResultFactory.success();
	}
}